class Solution {
public:

    string AfterTreatment(string& s)
    {
        string ret;
        for (auto ch : s)
        {
            if (ret.size() && ch == '#')
            {
                ret.pop_back();
            }
            else if (ret.size() == 0 && ch == '#') continue;
            else ret += ch;
        }
        return ret;
    }
    bool backspaceCompare(string s, string t) {
        string s1 = AfterTreatment(s);
        string s2 = AfterTreatment(t);

        return s1 == s2;

    }
};